﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.controllers.world {
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.interfaces.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;
    import net.wooga.pets.models.world.*;

    public class OnMoveToPositionFinishedCommand extends Command {

		[Inject]
        public var event:InfoEvent;
		[Inject]
        public var world:WorldModel;
		[Inject]
        public var userModel:UserModel;

        override public function execute():void{
            var _local3:IRoom;
            var _local4:IAvatar;
            var _local1:IMoving = (this.world.getActor(this.event.id) as IMoving);
            var _local2:IRoom = (this.world.getRoomById(_local1.roomId) as IRoom);
            if (_local1.nextRoomId){
                _local2.removeActor(_local1.id);
                _local3 = (this.world.getRoomById(_local1.nextRoomId) as IRoom);
                _local1.roomId = _local1.nextRoomId;
                _local1.nextRoomId = null;
                _local3.addActor(_local1);
                _local1.checkMove();
                if ((_local1 is ITreatable)){
                    dispatch(new InfoEvent(EventConstants.ON_PATIENT_LEFT_FROM_ROOM, ITreatable(_local1).id, {roomLeftFrom:_local2.id}));
                };
            } else {
                if ((_local1 is IBaby)){
                    _local2.handleBaby(IBaby(_local1), this.userModel.isVisitFriendsMode());
                } else {
                    if ((_local1 is ITreatable)){
                        _local2.handlePatient(ITreatable(_local1));
                    } else {
                        if ((_local1 is IAvatar)){
                            _local4 = IAvatar(_local1);
                            if (!_local4.currentAction){
                                _local4.handleNextAction();
                            };
                        };
                    };
                };
            };
        }

    }
}//package net.wooga.pets.controllers.world 
